package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.FileService;
import com.atguigu.spzx.model.vo.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "文件管理模块")
@RestController
@RequestMapping("/admin/system/file")
public class FileController {
    @Resource
    FileService fileService;
    @Operation(summary = "文件上传")
    @PostMapping("upload")
    @Parameters(
            value = {
//                    @Parameter(name="file" , description = "上传文件" ,in = ParameterIn.)
                    @Parameter(name = "module" , description = "文件保存的模块" , in = ParameterIn.QUERY)
            }
    )
    public Result<String> upload(MultipartFile file , // 前端上传文件的表单项name值为file 才可以默认接收
                                 String module){ //请求参数
        String path = fileService.upload(file,module);
        //返回上传成功的文件路径
        return Result.ok(path);
    }
    @Operation(summary = "文件删除")
    @PostMapping("delete")
    public Result delete(String path){ //请求参数
        fileService.delete(path);
        return Result.ok(null);
    }
}
